﻿@* --------------------------------------------------------------------------------------------------------------------
// <copyright file="EditTemplateRegions.cshtml" company="Devbridge Group LLC">
// 
// Copyright (C) 2015,2016 Devbridge Group LLC
// 
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// 
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
// 
// You should have received a copy of the GNU Lesser General Public License
// along with this program.  If not, see http://www.gnu.org/licenses/. 
// </copyright>
// 
// <summary>
// Better CMS is a publishing focused and developer friendly .NET open source CMS.
// 
// Website: https://www.bettercms.com 
// GitHub: https://github.com/devbridge/bettercms
// Email: info@bettercms.com
// </summary>
// -------------------------------------------------------------------------------------------------------------------- *@
@using BetterCms.Module.Pages.Content.Resources
@using BetterCms.Module.Pages.ViewModels.Templates
@using BetterCms.Module.Root.Content.Resources
@using BetterCms.Module.Root.Mvc.Grids.Extensions
@using BetterCms.Module.Root.Mvc.Grids.TableRenderers
@using MvcContrib.UI.Grid

@model TemplateEditViewModel
@{
    Action<ColumnBuilder<TemplateRegionItemViewModel>> columns = column =>
    {
        column.EditButtonColumn();

        column.For(model => Html.InlineEditColumnWithNamePattern(m => model.Identifier, "bcms-region-key", "bcms-old-region-key", "Regions[{0}].Identifier"))
            .Named(PagesGlobalization.TemplateRegions_IdentificatorColumn)
            .Sortable(false)
            .Attributes(@class => "bcms-option-key");

        column.For(model => Html.InlineEditColumnWithNamePattern(m => model.Description, "bcms-region-description", "bcms-old-region-description", "Regions[{0}].Description"))
           .Named(PagesGlobalization.TemplateRegions_DescriptionColumn)
           .Sortable(false)
           .Attributes(@class => "bcms-option-value");

        column.InlineEditControlsColumn(RootGlobalization.Button_Ok);
    };
}

<div class="bcms-top-block-holder">
     <div class="bcms-btn-main" id="bcms-add-region-button">@PagesGlobalization.TemplateRegions_AddNewRegion</div>
</div>

@Html.Grid(Model.Regions).Columns(columns).Attributes(@class => "bcms-tables", @id => "bcms-regions-grid").RowAttributes(delegate(GridRowViewData<TemplateRegionItemViewModel> row)
                  {
                      return new Dictionary<string, object>
                              {
                                    {"data-id", row.Item.Id},
                                    {"data-version", row.Item.Version}
                              };
                  }).RenderUsing(new EditableHtmlTableGridRenderer<TemplateRegionItemViewModel>())


<script type="text/html" id="bcms-editable-row-template">
    @(Html
        .Grid(new List<TemplateRegionItemViewModel> { new TemplateRegionItemViewModel() })
        .Columns(columns)
        .Attributes(@class => "bcms-tables")
        .RenderUsing(new HtmlTableGridSingleRowRenderer<TemplateRegionItemViewModel>()))
</script>
